package com.xf.system.controller;

import com.xf.system.common.facade.MenuFacade;
import com.xf.system.http.req.menu.MenuAddReqDTO;
import com.xf.system.http.req.menu.MenuListReqDTO;
import com.xf.system.http.req.menu.MenuUpdateReqDTO;
import com.xf.system.http.vo.menu.MenuTreeVO;
import com.xf.system.http.vo.menu.MenuVO;
import com.xf.system.response.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author xiefengf
 */
@Api(tags = "菜单服务Api")
@Slf4j
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuFacade menuFacade;

    @GetMapping("/listMenuTree")
    @Operation(summary = "当前菜单列表树形查询", method = "GET")
    public ApiResult<MenuVO> listMenuTree(@ModelAttribute MenuListReqDTO reqDto) {
        MenuVO vo = menuFacade.listMenuTree(reqDto);
        return ApiResult.success(vo);
    }

    @GetMapping("/listRoleMenuTree")
    @Operation(summary = "当前角色对应菜单列表树形查询", method = "GET")
    public ApiResult<MenuVO> listRoleMenuTree(@RequestParam("id") Long id) {
        MenuVO vo = menuFacade.listRoleMenuTree(id);
        return ApiResult.success(vo);
    }

    @GetMapping("/getMenuById/{id}")
    @Operation(summary = "通过菜单id查询菜单详情信息", method = "GET")
    public ApiResult<MenuTreeVO> getMenuById(@PathVariable("id") Long id) {
        MenuTreeVO vo = menuFacade.getMenuById(id);
        return ApiResult.success(vo);
    }

    @PostMapping("/saveMenu")
    @Operation(summary = "新增菜单信息", method = "POST")
    public ApiResult<Boolean> saveMenu(@RequestBody @Valid MenuAddReqDTO reqDto) {
        Boolean aBoolean = menuFacade.saveMenu(reqDto);
        return ApiResult.success(aBoolean);
    }

    @PutMapping("/updateMenu")
    @Operation(summary = "更新菜单信息", method = "PUT")
    public ApiResult<Boolean> updateMenu(@RequestBody @Valid MenuUpdateReqDTO reqDto) {
        Boolean aBoolean = menuFacade.updateMenu(reqDto);
        return ApiResult.success(aBoolean);
    }

    @DeleteMapping("/deleteMenu/{id}")
    @Operation(summary = "删除菜单信息", method = "DELETE")
    public ApiResult<Boolean> deleteMenu(@PathVariable(value = "id") Long id) {
        Boolean aBoolean = menuFacade.deleteMenu(id);
        return ApiResult.success(aBoolean);
    }

}
